package com.hzdp.sort;

/**
 * 时间复杂度O(n^2) 插入到已经有序的序列
 * 
 * @author liuming
 * 
 */
public class InsertSort {
	public static void insertSort(int[] array) {
		for (int i = 1; i < array.length; i++) {
			for (int j = i; j > 0; j--) {
				if (array[j] < array[j - 1]) {
					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
				}
			}
		}
	}

	public static void main(String[] args) {
		int[] array = { 2, 32, 10, 0, 2, 11, 30, 2, 4, 5, 1, 2 };
		insertSort(array);
		for (int i : array) {
			System.out.print(i + ",");
		}
	}
}
